//
//  HomeViewController.m
//  SafeFoodManagerDemo
//
//  Created by bob on 2017/10/13.
//  Copyright © 2017年 bob. All rights reserved.
//
#import "SafeFoodManagerDemo-Swift.h"
#import "HomeViewController.h"
#import "HomeTableHeadView.h"
#import "HomeFunTableViewCell.h"
#import "SettingViewController.h"
#import "MessageViewController.h"
#import "LoginStatuesModel.h"
#import "INAccountViewController.h"//进货台账
#import "OutAccountViewController.h"//出货台账
#import "CheckRecordViewController.h"//检查记录
#import "PeopleManagerViewController.h"//员工管理
#import "SupplyManagerViewController.h"//供应商管理
#import "GoodManagerViewController.h"//商品管理
#import "LookInforViewController.h"//商户资质
#import "MerchantManagerViewController.h"//商户管理
#import "OpenManagerViewController.h"//开办方管理
#import "GotoCheckViewController.h"//去调查
#import "ShopRegisterViewController.h"
#import "GetRegisterInforModel.h"
#import "JobListModel.h"
#import "INAcountEditViewController.h"
#import "TB_CollectionView.h"
#import "HomeCollectionViewCell.h"
#import "PatrolListViewController.h"
#import "OpenAndShopViewController.h"
#import "ItemReprotViewController.h"
#import "RecruitViewController.h"
#import "ExaminationViewController.h"
#import "HelpViewController.h"
#define headH 180*SCREEN_WIDTH/320.0
#define HeadMin 64
@interface HomeViewController ()<UICollectionViewDataSource,UICollectionViewDelegateFlowLayout>

@property(nonatomic,strong)HomeTableHeadView *headView;

@property(nonatomic,strong)TB_CollectionView *homeCollectionView;

@property (nonatomic, strong) UILabel *titleLabel;

@property (nonatomic, assign) CGFloat lastOffsetY;

@property(nonatomic,strong)LoginData *dataModel;

@property(nonatomic,strong)UIButton *msgBtn;//消息按钮

@property(nonatomic,copy)NSString*msgNum;

@property(nonatomic,assign)CGFloat Navalpha;



@end

@implementation HomeViewController

- (void)viewDidLoad {
    [super viewDidLoad];
   
    self.Navalpha=1;
    
    self.isHidenKeyToolBar=NO;

    self.dataModel=[LoginData mj_objectWithKeyValues:[LoginStatuesModel GetCach]];
    
     [self.view addSubview:self.headView];
    
    [self CustomNavBar];//导航栏
    
    if ([self getUserType]==2) {
        
        [self CreatHomeBtnWithName:@"去检查" isStoreHome:NO];
    }
    //获取登录信息，看信息是否存在改变

        [self getUserInfor];
    
    
    
    // Do any additional setup after loading the view.
}


-(void)viewWillAppear:(BOOL)animated
{
 [self.navigationController.navigationBar setBackgroundImage:[UIImage imageWithColor:kColorRGBA(0x2E4361, self.Navalpha)] forBarMetrics:UIBarMetricsDefault];

    [self getNewmsg];//获取新消息条数
    
}


-(HomeTableHeadView*)headView
{
    if (!_headView) {
        
        _headView=[[HomeTableHeadView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT)];
        
        switch (self.Utype) {
            case 1:
            {
                _headView.JobLabel.text=@"商户";
                
                _headView.NameLabel.text=self.dataModel.shopName;
                
                 [_headView.LogImageView LoadWebImageWithName:self.dataModel.shopImg andIsOrgin:NO];
            }
                break;
                
            case 2:
            {
                _headView.JobLabel.text=@"检查员";
                
                _headView.NameLabel.text=self.dataModel.staffName;
                
                  [_headView.LogImageView LoadWebImageWithName:self.dataModel.staffPhoto andIsOrgin:NO andPlaceImage:@"PeopleImage"];
            }
                break;
                
            case 3:
            {
                _headView.JobLabel.text=@"开办方";
                
                _headView.NameLabel.text=self.dataModel.staffName;
 
                [_headView.LogImageView LoadWebImageWithName:self.dataModel.staffPhoto andIsOrgin:NO andPlaceImage:@"PeopleImage"];
            }
                break;
                
                
            default:
            {
                _headView.JobLabel.text=@"管理员";
                
                  _headView.NameLabel.text=self.dataModel.staffName;
                
                   [_headView.LogImageView LoadWebImageWithName:self.dataModel.staffPhoto andIsOrgin:NO andPlaceImage:@"PeopleImage"];
            }
                break;
        }
        
       
        
        [_headView insertSubview:self.homeCollectionView atIndex:0];
    }
    
    return _headView;
}

-(TB_CollectionView*)homeCollectionView
{
    if (!_homeCollectionView) {
        
        UICollectionViewFlowLayout *layOut=[[UICollectionViewFlowLayout alloc]init];
        
        layOut.scrollDirection=UICollectionViewScrollDirectionVertical;//垂直滚动
        
        layOut.sectionInset=UIEdgeInsetsMake(0, 0, 0, 0);
        
        _homeCollectionView=[[TB_CollectionView alloc]initWithFrame:CGRectMake(0,0, SCREEN_WIDTH, SCREEN_HEIGHT) collectionViewLayout:layOut];
        
        _homeCollectionView.delegate=self;
        
        _homeCollectionView.dataSource=self;
        
        _homeCollectionView.contentInset=UIEdgeInsetsMake(headH, 0, 0, 0);
   
        _homeCollectionView.bounces=YES;
        
        _lastOffsetY=-headH;
        
        [_homeCollectionView registerNib:[UINib nibWithNibName:@"HomeCollectionViewCell" bundle:nil] forCellWithReuseIdentifier:@"cell"];
      
    }
    
    return _homeCollectionView;
    
}


-(UILabel*)titleLabel
{
    if (!_titleLabel) {
        
        _titleLabel= [[UILabel alloc] init];

        _titleLabel.text=@"首页";
        
        _titleLabel.font = [UIFont  boldSystemFontOfSize:21];
        
        [_titleLabel setTextColor:[UIColor colorWithWhite:1 alpha:0]];
        
        [_titleLabel sizeToFit];
        
    }
    
    return _titleLabel;
}

-(void)CustomNavBar{

    // 设置导航条中间view

    self.navigationItem.titleView = self.titleLabel;
    // 导航条背景透明
    [self.navigationController.navigationBar setBackgroundImage:[[UIImage alloc] init] forBarMetrics:UIBarMetricsDefault];

    [self.navigationController.navigationBar setShadowImage:[[UIImage alloc] init]];
    
    [self addNavigationItemWithImageNames:@[@"percent"] isLeft:YES target:self action:@selector(PersionCenter) tags:nil];
    
    UIBarButtonItem * item = [[UIBarButtonItem alloc] initWithCustomView:self.msgBtn];
    
    self.navigationItem.rightBarButtonItem=item;


    kAppWindow.backgroundColor=TBColorAppTheme;
    
}


-(UIButton*)msgBtn
{
    if (!_msgBtn) {
        
        _msgBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        
        [_msgBtn setImage:[UIImage imageNamed:@"message"] forState:UIControlStateNormal];
        
         [_msgBtn setImage:[UIImage imageNamed:@"messageH"] forState:UIControlStateSelected];
        
        _msgBtn.frame = CGRectMake(0, 0, 30, 30);
     
        [_msgBtn setImageEdgeInsets:UIEdgeInsetsMake(0, 10, 0, 0)];
      
        [_msgBtn addTarget:self action:@selector(MessageCenter) forControlEvents:UIControlEventTouchUpInside];
 
        
    }
    
    return _msgBtn;
}

#pragma mark-tableView代理方法



-(NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView
{
    
    return 1;
    
}


-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    
      return self.dataModel.menus.count;
    
}

- (__kindof UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    LoginMenus *meaue=self.dataModel.menus[indexPath.row];
    
    HomeCollectionViewCell *cell=[collectionView dequeueReusableCellWithReuseIdentifier:@"cell" forIndexPath:indexPath];
    
    cell.funNameLabel.text=meaue.name;
    
    cell.funImageLabel.image=[UIImage imageNamed:meaue.icon];
    
    return cell;
    
}

- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout minimumInteritemSpacingForSectionAtIndex:(NSInteger)section
{
    
    return 1;
    
}

- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout minimumLineSpacingForSectionAtIndex:(NSInteger)section
{
    
    return 1;
    
    
}


- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath
{
    
    CGSize size=CGSizeMake((SCREEN_WIDTH-2)/3.0, (SCREEN_WIDTH-2)/3.0);
    
    return size;
    
}



-(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
    LoginMenus *meaue=self.dataModel.menus[indexPath.row];
    
    [self.navigationController.navigationBar setBackgroundImage:[UIImage imageWithColor:kColorRGBA(0x2E4361, 1)] forBarMetrics:UIBarMetricsDefault];
    
    switch (meaue.ID) {
        case 1:
        {
            if ([self getUserType]==1) {
                
                INAcountEditViewController *inAE=[INAcountEditViewController new];
                
                [self.navigationController pushViewController:inAE animated:YES];
                
            }else{
                
                INAccountViewController *InAcount=[INAccountViewController new];
                InAcount.segmentedArray= [[NSArray alloc]initWithObjects:@"餐饮/流通",@"农产品",nil];
                
                [self.navigationController pushViewController:InAcount animated:YES];
                
            }
        }
            break;
        case 2:
        {
            JobListModel *list=[JobListModel new];
            
            OutAccountViewController *OutAcount=[OutAccountViewController new];
            
            if ([self getUserType]==1) {
                
                OutAcount.isEdit=YES;
                
                OutAcount.isdeleMore=YES;
                
                list.shopId=[LoginStatuesModel shopId];
                
            }else{
                
                OutAcount.isEdit=NO;
                
                OutAcount.isdeleMore=NO;
                
                if ([self getUserType]==3) {
                    
                    list.marketId=[LoginStatuesModel getStaffId];
                }
                
            }
            
            OutAcount.AddBtnTitle=@"新增出货";
            
            OutAcount.searchName=@"输入关键字";
            
            OutAcount.title=@"出货台账";
            
            OutAcount.Reqmodel=list;
            
            [self.navigationController pushViewController:OutAcount animated:YES];
        }
            break;
        case 3:
        {
            
            if ([self getUserType]==2||[self getUserType]==4) {
                
                //检查员和开办方
                OpenAndShopViewController *OpenAndSearch=[OpenAndShopViewController new];
                
                OpenAndSearch.pushType=0;
                
                [self.navigationController pushViewController:OpenAndSearch animated:YES];
    
            }else{
                
                
                JobListModel *list=[JobListModel new];
                
                CheckRecordViewController *CheckR=[CheckRecordViewController new];
                
                CheckR.isEdit=NO;
                
                CheckR.isdeleMore=NO;
                
                if ([self getUserType]==3) {
                    
                    list.marketId=[LoginStatuesModel getStaffId];
                    
                    list.ptype=@"2";
                    
                    list.type=[NSString stringWithFormat:@"%ld",[LoginStatuesModel shoptype]];
                    
                }else{
                    
                    list.shopId=[LoginStatuesModel shopId];
                    
                    list.ptype=@"1";
                    
                    list.type=[NSString stringWithFormat:@"%ld",[LoginStatuesModel shoptype]];
                    
                }
                
                CheckR.searchName=@"输入关键字";
                
                CheckR.Reqmodel=list;
                
                CheckR.title=@"检查记录";
                
                CheckR.isAutoLoding=YES;
                
                [self.navigationController pushViewController:CheckR animated:YES];
                
                
            }
            
            
        }
            break;
            
        case 4:
        {
            PeopleManagerViewController *People=[PeopleManagerViewController new];
            
            People.title=meaue.name;
            
            [self.navigationController pushViewController:People animated:YES];
        }
            break;
            
        case 5:
        {
            JobListModel *list=[JobListModel new];
            
            SupplyManagerViewController *Supply=[SupplyManagerViewController new];
            
            
            if ([self getUserType]==1) {
                
                Supply.isEdit=YES;
                
                Supply.isdeleMore=YES;
                
                list.shopId=[LoginStatuesModel shopId];
            }else{
                
                Supply.isEdit=NO;
                
                Supply.isdeleMore=NO;
                
                if ([self getUserType]==3) {
                    
                    list.marketId=[LoginStatuesModel getStaffId];
                }
                
            }
            
            Supply.Reqmodel=list;
            
            Supply.searchName=@"输入供应商名称";
            Supply.AddBtnTitle=@"新增供应商";
            Supply.title=@"供应商列表";
            [self.navigationController pushViewController:Supply animated:YES];
        }
            break;
        case 6:
        {
            GoodManagerViewController *Goods=[GoodManagerViewController new];
            
            [self.navigationController pushViewController:Goods animated:YES];
        }
            break;
        case 7:
        {
            if (self.Utype==1) {
                //商户->审核通过与审核不通过
                if ([LoginStatuesModel shopStatus]==0) {
                    //待审核状态
                    
                    GetRegisterInforModel *shopmodel=[GetRegisterInforModel new];
                    
                    shopmodel.type=[NSString stringWithFormat:@"%ld",[LoginStatuesModel shoptype]];
                    
                    shopmodel.shopId=[NSString stringWithFormat:@"%ld",[LoginStatuesModel shopId]];
                    
                    shopmodel.token=[LoginStatuesModel getUserToken];
                    
                    ShopRegisterViewController *Edit=[ShopRegisterViewController new];
                    
                    Edit.title=@"商户资质";
                    
                    Edit.BtnStr=@"保存";
                    
                    Edit.OptionSussStr=@"保存成功";
                    
                    Edit.requrl=@"/index.php/FoodCheckApi/shopRegInfo.json";
                    
                    Edit.Reqmodel=shopmodel;
                    
                    Edit.postUrl=@"/index.php/FoodCheckApi/shopReg.json";
                    
                    Edit.block=^()
                    {
                        
                        
                    };
                    
                    [self.navigationController pushViewController:Edit animated:YES];
                    
                }else{
                    LookInforViewController *Infor=[LookInforViewController new];
                    
                    Infor.reqUrl=@"/index.php/FoodCheckApi/shopDetail.json";
                    
                    Infor.params=@{@"shopId":[NSString stringWithFormat:@"%ld",[LoginStatuesModel shopId]]};
                    
                    Infor.title=@"商户详情";
                    
                    [self.navigationController pushViewController:Infor animated:YES];
                    
                }
                
            }else if (self.Utype==3)
            {
                //开办方
                
                GetRegisterInforModel *Openmodel=[GetRegisterInforModel new];
                
                Openmodel.type=[NSString stringWithFormat:@"%ld",[LoginStatuesModel shoptype]];
                
                Openmodel.marketId=[NSString stringWithFormat:@"%ld",[LoginStatuesModel getStaffId]];
                
                Openmodel.token=[LoginStatuesModel getUserToken];
                
                ShopRegisterViewController *OpenLook=[ShopRegisterViewController new];
                
                OpenLook.title=@"开办方资质";
                
                OpenLook.BtnStr=@"保存";
                
                OpenLook.OptionSussStr=@"保存成功";
                
                OpenLook.requrl=@"/index.php/FoodCheckApi/marketRegInfo.json";
                
                OpenLook.Reqmodel=Openmodel;
                
                OpenLook.postUrl=@"/index.php/FoodCheckApi/marketReg.json";
                
                OpenLook.block=^()
                {
                    
                    
                };
                
                [self.navigationController pushViewController:OpenLook animated:YES];
                
            }
            
            
        }
            break;
        case 8:
        {
            JobListModel *list=[JobListModel new];
            
            MerchantManagerViewController *Merchant=[MerchantManagerViewController new];
            
            if ([self getUserType]==3) {
                //开办方需要传markid
                Merchant.isEdit=YES;
                
                Merchant.isdeleMore=YES;
                
                list.marketId=[LoginStatuesModel getStaffId];
                
            }else if ([self getUserType]==2)
            {
                //检查员可以编辑商户
                
                Merchant.isEdit=YES;
                
                Merchant.isdeleMore=YES;
                
            }else{
                
                //管理员只能查看
                Merchant.isEdit=YES;
                
                Merchant.isdeleMore=YES;
       
            }
            
            Merchant.searchName=@"输入商户名称";
            Merchant.AddBtnTitle=@"新增商户";
            Merchant.Reqmodel=list;
            
            Merchant.title=@"商户列表";
            
            Merchant.pushType=0;
            
            [self.navigationController pushViewController:Merchant animated:YES];
        }
            break;
            
        case 9:
        {
            JobListModel *list=[JobListModel new];
            
            OpenManagerViewController *OpenM=[OpenManagerViewController new];
            
            if ([self getUserType]==2)
            {
                //检查员可以编辑商户
                
                OpenM.isEdit=YES;
                
                OpenM.isdeleMore=YES;
                
            }else{
                
                //管理员只能查看
                OpenM.isEdit=YES;
                
                OpenM.isdeleMore=YES;
                
            }
            
            OpenM.searchName=@"输入开办方名称";
            OpenM.AddBtnTitle=@"新增开办方";
            OpenM.Reqmodel=list;
            
            OpenM.title=@"开办方列表";
            
            OpenM.pushType=0;
            
            [self.navigationController pushViewController:OpenM animated:YES];
            
        }
            break;
            
          case 10:
        {
            ItemReprotViewController *ItemReport=[ItemReprotViewController new];
            
            [self.navigationController pushViewController:ItemReport animated:YES];
            
        }
            break;
            
          case 11:
        {
         
            if ([self getUserType]==2||[self getUserType]==4) {
                
                //检查员和开办方
                OpenAndShopViewController *OpenAndSearch=[OpenAndShopViewController new];
        
                OpenAndSearch.pushType=1;
                
                [self.navigationController pushViewController:OpenAndSearch animated:YES];
                
            }else{
                
                JobListModel *list=[JobListModel new];
                
                PatrolListViewController *Patro=[PatrolListViewController new];
                
                Patro.isEdit=NO;
                
                Patro.isdeleMore=NO;
                
                Patro.isGroupStyle=YES;
                
                list.type=[NSString stringWithFormat:@"%ld",[LoginStatuesModel shoptype]];
                
                if ([self getUserType]==1) {
                    
                    list.ptype=@"1";
                    
                    list.shopId=[LoginStatuesModel shopId];
                    
                }else{
                    
                    list.ptype=@"2";
                    
                    list.marketId=[LoginStatuesModel getStaffId];
                    
                }
          
                Patro.Reqmodel=list;
                
                Patro.searchName=@"输入日志";
                Patro.AddBtnTitle=@"新增日志";
                Patro.title=@"检查日志";
                [self.navigationController pushViewController:Patro animated:YES];
            }
        }
            break;
        case 12://招聘
        {
            RecruitViewController *Patro=[RecruitViewController new];
            JobListModel *list=[JobListModel new];
            list.pageOn = YES;
            list.pageSize = 10;
            list.currentPage = 1;
            
            Patro.ishidenSearch = NO;
            Patro.Reqmodel = list;
            Patro.isEdit= [LoginStatuesModel getUserType]==1?YES:NO;
            Patro.isdeleMore=YES;
            Patro.isGroupStyle=YES;
            Patro.searchName=@"输入职位名称";
            Patro.AddBtnTitle=@"新增招聘";
            Patro.title=@"招聘管理";
            [self.navigationController pushViewController:Patro animated:YES];
        }
            break;
        case 13://考试
        {
            ExaminationViewController *Patro=[ExaminationViewController new];
            JobListModel *list=[JobListModel new];
            list.pageOn = YES;
            list.pageSize = 50;
            list.currentPage = 1;
            list.ptype = @"1";
            
            Patro.ishidenSearch = NO;
            Patro.Reqmodel = list;
            Patro.isEdit= [LoginStatuesModel getUserType]==4?NO:YES;
            Patro.isdeleMore=NO;
            Patro.isGroupStyle=YES;
            Patro.searchName=@"请输入试卷名称";
            Patro.AddBtnTitle=@"开始考试";
            Patro.title=@"考试记录";
            [self.navigationController pushViewController:Patro animated:YES];
        }
            break;
            case 14:
        {
            HelpViewController *Patro=[HelpViewController new];
            JobListModel *list=[JobListModel new];
            list.pageOn = YES;
            list.pageSize = 10;
            list.currentPage = 1;
            
            Patro.ishidenSearch = YES;
            Patro.Reqmodel = list;
            Patro.isEdit=NO;
            Patro.isdeleMore=NO;
            Patro.isGroupStyle=YES;
            
            [self.navigationController pushViewController:Patro animated:YES];
        }
            break;
            case 15:
        {
            [self.navigationController pushViewController:[ArticleTableViewController new] animated:YES];
            
        }
        default:
            
            break;
    }
    
}

-(void)scrollViewDidScroll:(UIScrollView *)scrollView
{
    //获取当前偏移量
    CGFloat offsetY = scrollView.contentOffset.y;
    
    //获取偏移量差值
    CGFloat delta=offsetY-_lastOffsetY;
    
    CGFloat headx=-offsetY;
    if (headx<HeadMin) {
        
        headx=HeadMin;
    }
    
    _headView.headHeightCanst.constant=headx;
    
    CGFloat alpha=delta/(headH-HeadMin-30);
    
    UIColor *alphaColor = [UIColor colorWithWhite:1 alpha:alpha];
    
    [_titleLabel setTextColor:alphaColor];
    
    self.Navalpha=alpha>=1?0.99:alpha;//如果为1的话，会便宜64的像素
    
    [self.navigationController.navigationBar setBackgroundImage:[UIImage imageWithColor:kColorRGBA(0x2E4361, alpha)] forBarMetrics:UIBarMetricsDefault];
 
}


#pragma mark-导航栏事件
-(void)PersionCenter
{
   
    SettingViewController *Setting=[SettingViewController new];
  
    [self.navigationController pushViewController:Setting animated:YES];
    
}

-(void)MessageCenter
{
   
    
    MessageViewController *message=[MessageViewController new];
    
    message.NoreadNum=self.msgNum;
   
     [self.navigationController pushViewController:message animated:YES];
    
    
   
}

#pragma mark-检查员去检查

-(void)GotoHome:(UIButton*)sender
{
     [sender.layer pop_removeAllAnimations];
    
    [self.navigationController.navigationBar setBackgroundImage:[UIImage imageWithColor:kColorRGBA(0x2E4361, 1)] forBarMetrics:UIBarMetricsDefault];
    
    GotoCheckViewController *GotoCheckNew=[GotoCheckViewController new];

    GotoCheckNew.userType=1;//检查类型

    [self.navigationController pushViewController:GotoCheckNew animated:YES];
    
    
//    OpenAndShopViewController *OpenAndSearch=[OpenAndShopViewController new];
//    
//    OpenAndSearch.pushType=2;
//    
//    [self.navigationController pushViewController:OpenAndSearch animated:YES];
    
}


#pragma mark-获取登录信息

-(void)getUserInfor
{
    BaseReqApi *Api=[[BaseReqApi alloc]initWithRequestUrl:@"/index.php/FoodCheckApi/loginInfo.json" andrequestTime:5 andParams:@{} andRequestMethod:YTKRequestMethodPOST andCache:NO andCacheTime:0 andPostToken:YES];
    
    [Api StarRequest:^(TBResponseStatus responseStatus, NSString *message, id responseObject) {
   
        LoginStatuesModel *model=[LoginStatuesModel mj_objectWithKeyValues:responseObject];
        
        if (responseStatus==1) {
        
            NSLog(@"%@",[HelpWay dictionaryToJSON:responseObject]);
            
            model.data.token=[LoginStatuesModel getUserToken];
            
            model.data.loginType=[LoginStatuesModel getUserType];
            
            [LoginStatuesModel SaveUserInforWithModel:model];
            
            dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
                
                [self.homeCollectionView reloadData];

                
            });
    
        }
    }];
    
}

#pragma mark-获取新消息条数
-(void)getNewmsg
{
    
    NSString *readid=@"";
    if ([self getUserType]==1) {
        
        readid=[NSString stringWithFormat:@"%ld",[LoginStatuesModel shopId]];
    }else{
        
        readid=[NSString stringWithFormat:@"%ld",[LoginStatuesModel getStaffId]];
    }
    
    BaseReqApi *Api=[[BaseReqApi alloc]initWithRequestUrl:@"/index.php/FoodCheckApi/messageNewTotal.json" andrequestTime:5 andParams:@{@"loginType":[NSString stringWithFormat:@"%ld",[LoginStatuesModel getUserType]],@"readerId":readid} andRequestMethod:YTKRequestMethodPOST andCache:NO andCacheTime:0 andPostToken:YES];
    
    [Api StarRequest:^(TBResponseStatus responseStatus, NSString *message, id responseObject) {
        
  
        if (responseStatus==1) {
            
            NSLog(@"%@",responseObject);
           
            if ([responseObject[@"data"]intValue]==0) {
                
                self.msgNum=@"";
                
                self.msgBtn.selected=NO;
            }else{
            
                self.msgBtn.selected=YES;
                
                self.msgNum=[responseObject[@"data"]stringValue];
                
            }
        }
    }];
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
